import JNFrameTween from "./JNFrameTween";


export default class JNFrameTweenSystem {

    private tweens:JNFrameTween<{}>[] = [];
    private _addTime:number = 0;
    get addTime(){return this._addTime}
    
    /**
     * @en
     * Gets the instance of the tween system.
     * @zh
     * 获取缓动系统的实例。
     */
    static _instance: JNFrameTweenSystem;

    addTween<T>(tween:JNFrameTween<T>){
        this.tweens.push(tween);
    }

    hasTween(tween:JNFrameTween<{}>){
        return this.tweens.indexOf(tween) >= 0;
    }

    delTween<T>(tween:JNFrameTween<T>){
        this.tweens.splice(this.tweens.indexOf(tween),1);
    }

    static getInstance(): JNFrameTweenSystem {
        if(JNFrameTweenSystem._instance)
            return JNFrameTweenSystem._instance;
        return JNFrameTweenSystem._instance = new JNFrameTweenSystem();
    }

    static deleteInstance(){
        JNFrameTweenSystem._instance = null;
    }

    onUpdate(dt:number){
        this._addTime += dt;
        this.tweens.forEach(tween => {
            tween.update(this.addTime);
        });
    }

}


